package com.csp.base.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.csp.base.model.JobAndTrigger;

@Mapper
public interface JobAndTriggerMapper {
	/**
	 * 列表查询
	 * @return
	 */
	@Select(
			"SELECT "+
			"qrtz_job_details.JOB_STATUS, "+
			"qrtz_job_details.JOB_NAME, "+
			"qrtz_job_details.JOB_GROUP, "+
			"qrtz_job_details.JOB_CLASS_NAME, "+
			"qrtz_triggers.TRIGGER_NAME, "+
			"qrtz_triggers.TRIGGER_GROUP, "+
			"qrtz_cron_triggers.CRON_EXPRESSION, "+
			"qrtz_cron_triggers.TIME_ZONE_ID "+
			"FROM qrtz_job_details "+
			"JOIN qrtz_triggers "+
			"JOIN qrtz_cron_triggers ON qrtz_job_details.JOB_NAME = qrtz_triggers.JOB_NAME "+
			"AND qrtz_triggers.TRIGGER_NAME = qrtz_cron_triggers.TRIGGER_NAME "+
			"AND qrtz_triggers.TRIGGER_GROUP = qrtz_cron_triggers.TRIGGER_GROUP "+
			"ORDER BY  create_time DESC "
			)
	public List<JobAndTrigger> getJobAndTriggerDetails();

	/**
	 * 更改运行状态
	 * @param jobName
	 * @param jobGroup
	 * @param stopping
	 */
	@Update(
			"UPDATE qrtz_job_details SET "+
			"JOB_STATUS=#{JOB_STATUS} "+
			"WHERE "+
			"JOB_NAME=#{JOB_NAME} AND JOB_GROUP=#{JOB_GROUP} "
			)
	public void updateJobStatusByJobName$JobGroup(@Param("JOB_NAME")String jobName,@Param("JOB_GROUP")String jobGroup,@Param("JOB_STATUS")String status);
}
